import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { SCopyChoiceTempleInfo } from "../../../../../Message/Public/SCopyChoiceTempleInfo";
import { Language } from "../../../../../extend/language/Language";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { BossConfig } from "../../../resource/BossConfig";
import { SceneRange } from "../../../scene/map/SceneRange";
import { Global } from "../../../../../com/gengine/global/Global";
import { TweenMax } from "../../../../../com/greensock/TweenMax";
import { Quint } from "../../../../../com/greensock/easing/Quint";
import { TaskCache } from "../../../cache/TaskCache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { MagicTowerInfoTitle } from "../magicTower/MagicTowerInfoTitle";
import { TowerInfoHideButton } from "../magicTower/TowerInfoHideButton";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { SecTimerView } from "../../common/SecTimerView";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class FaneCopyInfoPanel
    
    export  class FaneCopyInfoPanel extends View
    {
        constructor()
        {
            super();
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this._passTxtArray = [];
            this._passNameArray = [];
            this._itemArray = [];
            this.mouseEnabled = false;
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            return;
        }

        public updateByTempleInfo(arg1: SCopyChoiceTempleInfo): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            if (arg1) 
            {
                this._timeView.setLeftTime(arg1.remainTime);
                loc1 = arg1.killBossNum;
                loc2 = 0;
                while (loc2 < loc1) 
                {
                    if (loc3 = this._passTxtArray[loc2]) 
                    {
                        loc3.htmlText = this._passNameArray[loc2] + "    " + Language.getString(58009);
                    }
                    ++loc2;
                }
            }
            return;
        }

        public updateReward(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._itemArray.length) 
            {
                loc1 = this._itemArray[loc2] as BaseItem;
                loc1.itemData = new ItemData(int(arg1[loc2]));
                ++loc2;
            }
            return;
        }

        /* internal  */updatePassCondition(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=[2201009, 2201010, 2201011, 2201012, 2201013, 2201014, 2201015, 2201016];
            var loc6=0;
            while (loc6 < this._passTxtArray.length) 
            {
                loc3 = BossConfig.instance.getInfoByName(int(loc1[2 * loc6]));
                loc4 = BossConfig.instance.getInfoByName(int(loc1[2 * loc6 + 1]));
                loc2 = this._passTxtArray[loc6];
                loc5 = Language.getStringByParam(58007, loc3.name + " / " + loc4.name);
                loc2.text = loc5;
                if (this._passNameArray.length < 4) 
                {
                    this._passNameArray.push(loc5);
                }
                ++loc6;
            }
            return;
        }

        /* internal  */onZoomBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._zoomBtn.show) 
            {
                this.hidePanel();
            }
            else 
            {
                this.showPanel();
            }
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 30;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public updatePosition(): void
        {
            if (this._zoomBtn.show) 
            {
                x = SceneRange.display.width - 284;
                y = 180 + 20 * SceneRange.display.height / 1000;
            }
            else 
            {
                x = SceneRange.display.width - 260;
                y = 288;
            }
            return;
        }

        public updateStatus(arg1: string): void
        {
            if (arg1 != FaneCopyInfoPanel.Expand) 
            {
                if (arg1 == FaneCopyInfoPanel.Shrink) 
                {
                    this._zoomBtn.show = false;
                    if (this._bodySp.parent) 
                    {
                        removeChild(this._bodySp);
                    }
                }
            }
            else 
            {
                this._zoomBtn.show = true;
                if (!this._bodySp.parent) 
                {
                    addChild(this._bodySp);
                }
            }
            return;
        }

        public hidePanel(): void
        {
            if (this._showTween && this._showTween.active) 
            {
                this._showTween.kill();
            }
            x = SceneRange.display.width - 260;
            y = 288;
            this._hideTween = TweenMax.to(this._bodySp, 0.2, {"x": 260, "ease": Quint.easeOut, "onComplete": this.onHideEnd});
            this._zoomBtn.show = false;
            return;
        }

        /* internal  */onHideEnd(): void
        {
            if (this._bodySp.parent) 
            {
                removeChild(this._bodySp);
            }
            return;
        }

        public showPanel(): void
        {
            if (TaskCache.showTrack) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            }
            if (this._hideTween && this._hideTween.active) 
            {
                this._hideTween.kill();
            }
            x = SceneRange.display.width - 284;
            y = 180 + 20 * SceneRange.display.height / 1000;
            this._showTween = TweenMax.to(this._bodySp, 0.2, {"x": 0, "ease": Quint.easeIn});
            this._zoomBtn.show = true;
            if (!this._bodySp.parent) 
            {
                addChild(this._bodySp);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            Dispatcher.addEventListener(EventName.TrackClick, this.onTaskTrackClick);
            return;
        }

        /* internal  */onTaskTrackClick(arg1: DataEvent): void
        {
            if (arg1.data && this._zoomBtn.show) 
            {
                this.hidePanel();
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.removeEventListener(EventName.TrackClick, this.onTaskTrackClick);
            return;
        }

        
        {
            FaneCopyInfoPanel.Expand = "伸展";
            FaneCopyInfoPanel.Shrink = "收缩";
        }

        protected createChildren(): void
        {
            var loc2=null;
            var loc4=null;
            var loc6=null;
            var loc7=null;
            this._bodySp = new Object /* flash.display.Sprite */();
            this._bodySp.mouseEnabled = false;
            this.addChild(this._bodySp);
            this._bg = new Object /* flash.display.Bitmap */(new Object /* flash.display.BitmapData */(260, 330, false, 0));
            this._bg.alpha = 0.45;
            this._bg.y = 20;
            this._bodySp.addChild(this._bg);
            this._moveBtn = ObjCreate.createGButton("", 0, 0, 24, 22, this._bodySp, "MoveBtn");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(60068), "#FFFFFF");
            this._titleSp = new MagicTowerInfoTitle();
            this._titleSp.x = 24;
            this._titleSp.y = -4;
            this._titleSp.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._bodySp.addChild(this._titleSp);
            this._zoomBtn = new TowerInfoHideButton();
            this._zoomBtn.x = 248;
            this._zoomBtn.y = 11;
            this.addChild(this._zoomBtn);
            this._zoomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onZoomBtnClick);
            this._conditionPanel = new Object /* flash.display.Sprite */();
            this._conditionPanel.x = 0;
            this._conditionPanel.y = 12;
            this._bodySp.addChild(this._conditionPanel);
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            loc2 = ObjCreate.createGTextField(Language.getString(50030), 10, 10, 200, 20, this._conditionPanel, loc1);
            var loc3=new GTextFormat(FontUtil.songtiName, 18, 65280, true);
            this._timeView = ObjCreate.createSecTimeView("mm: ss", 0, 27, 260, 20, this._conditionPanel, loc3);
            this._timeView.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createGTextField(Language.getString(60360), 10, 50, 200, 20, this._conditionPanel);
            var loc5=0;
            while (loc5 < 4) 
            {
                (loc4 = ObjCreate.createGTextField("", 10, 70 + loc5 * 20, 200, 20, this._conditionPanel)).autoSize = flash.text.TextFieldAutoSize.LEFT;
                this._passTxtArray.push(loc4);
                ++loc5;
            }
            ObjCreate.createBg(5, 150, 245, 2, this._conditionPanel, ImagesConst.SplitLine);
            this._tipTxt = ObjCreate.createGTextField("", 10, 160, 230, 20, this._conditionPanel);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.multiline = true;
            this._tipTxt.wordWrap = true;
            this._tipTxt.text = Language.getString(58008);
            this._rewardsPanel = new Object /* flash.display.Sprite */();
            this._rewardsPanel.x = 0;
            this._rewardsPanel.y = 230;
            this._bodySp.addChild(this._rewardsPanel);
            ObjCreate.createGTextField(Language.getString(36293), 10, 10, 200, 20, this._rewardsPanel, GlobalStyle.textFormat6);
            ObjCreate.createGTextField(Language.getString(80273), 10, 40, 200, 20, this._rewardsPanel, GlobalStyle.textFormat6);
            ObjCreate.createGTextField(Language.getString(80274), 10, 85, 200, 20, this._rewardsPanel, GlobalStyle.textFormat6);
            var loc8=0;
            while (loc8 < 8) 
            {
                loc7 = ObjCreate.createBg(60 + loc8 % 4 * 45, 30 + Math.floor(loc8 / 4) * 45, 38, 38, this._rewardsPanel, ImagesConst.PackItemBg);
                (loc6 = new BaseItem()).setSize(32, 32);
                loc6.x = loc7.x + 3;
                loc6.y = loc7.y + 3;
                this._rewardsPanel.addChild(loc6);
                this._itemArray.push(loc6);
                ++loc8;
            }
            return;
        }

        public updateByCopyInfo(arg1: TCopy): void
        {
            if (arg1) 
            {
                this._titleSp.title = HTMLUtil.addColor(arg1.name, GlobalStyle.color2);
                this._timeView.setLeftColor(300, "#ff0000");
                if (arg1.reward && !(arg1.reward == "0") && !(arg1.reward == "")) 
                {
                    this.updateReward(arg1.reward.split(","));
                }
                this.updatePassCondition();
            }
            return;
        }

        /* internal */ /* var */_moveRec: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_hideTween: TweenMax;

        /* internal */ /* var */_showTween: TweenMax;

        /* internal */ /* var */_bodySp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_titleSp: MagicTowerInfoTitle;

        /* internal */ /* var */_zoomBtn: TowerInfoHideButton;

        /* internal */ /* var */_conditionPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_rewardsPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_timeView: SecTimerView;

        /* internal */ /* var */_passTxtArray: Array<any>;

        /* internal */ /* var */_passNameArray: Array<any>;

        /* internal */ /* var */_tipTxt: GTextFiled;

        /* internal */ /* var */_itemArray: Array<any>;

        public static /* var */Shrink: string="收缩";

        public static /* var */Expand: string="伸展";
    }
